package com.moxiao.yfjh.module.activity.api;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.moxiao.yfjh.framework.common.util.date.DateUtils;
import com.moxiao.yfjh.module.activity.dal.dataobject.activityEnroll.ActivityEnrollDO;
import com.moxiao.yfjh.module.activity.dal.dataobject.activityInfo.ActivityInfoDO;
import com.moxiao.yfjh.module.activity.dal.mysql.activityEnroll.ActivityEnrollMapper;
import com.moxiao.yfjh.module.activity.dal.mysql.activityInfo.ActivityInfoMapper;
import com.moxiao.yfjh.module.activity.service.ActivityInfoApiService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.Objects;

@Service
@Validated
public class ActivityInfoApiServiceImpl implements ActivityInfoApiService {

    @Resource
    private ActivityInfoMapper infoMapper;
    @Resource
    private ActivityEnrollMapper enrollMapper;

    @Override
    public Integer getActivityInfoApiNum(Long userId) {
        return infoMapper.getActivityNum(userId, DateUtils.getMonthFirstDay(), DateUtils.getMonthLastDay());
    }

    @Override
    public Boolean getMemberActivityInfo(Long userId) {
        LambdaQueryWrapper<ActivityInfoDO> lqw = Wrappers.lambdaQuery();
        lqw.eq(ActivityInfoDO::getHeadUserId, userId);
        lqw.last("LIMIT " + 1);
        ActivityInfoDO activityInfoDO = infoMapper.selectOne(lqw);
        return Objects.nonNull(activityInfoDO);
    }

    @Override
    public Boolean getMemberEnroll(Long userId) {
        LambdaQueryWrapper<ActivityEnrollDO> lqw = Wrappers.lambdaQuery();
        lqw.eq(ActivityEnrollDO::getUserId, userId);
        lqw.last("LIMIT " + 1);
        ActivityEnrollDO enrollDO = enrollMapper.selectOne(lqw);
        return Objects.nonNull(enrollDO);
    }
}
